package cate.game.rank.h;

import cate.game.framework.GameException;
import cate.game.rank.po.HeroRank;
import cate.game.rank.po.HeroRankSPO;
import cate.game.rank.vo.RankParam;
import cate.game.role.Role;
import cate.game.role.bag.hero.Hero;

public abstract class HeroRankHandler extends ConditionRankHandler<HeroRankSPO, HeroRank> implements IConditionRankHandler{
    /**
     * 记录,默认只支持一个value的排行
     */
    @Override
    public final void record(Role role, long newValue) {
        throw new GameException().content("不支持的方法");
    }

    public final void record(Role role, Hero hero, long power) {
        if (power < getConditionValue()) {
            return;
        }
        RankParam param = RankParam.build(role);
        long preValue = getRankValue(param, 0);
        synchronized(this){
            getSPO(gameBody).record(role, hero, power);
            save();
            hero.clearExtraData();
        }
        afterRecord(preValue, param);
    }
}
